package com.jukte.recipe.utils;

import com.ewhat.recipes.R;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;



public class SpecialCheckBox extends ImageView implements View.OnClickListener{
	private boolean checked=false;
	private SpecialCheckBox.OnClickListener lsn;
	public SpecialCheckBox(Context context) {
		super(context);
		init();
	}
	public SpecialCheckBox(Context context,AttributeSet tr) {
		super(context,tr);
		init();
	}
	public SpecialCheckBox(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		init();
	}
	
	public void init(){
		this.setImageResource(R.drawable.checkfalse);
		this.checked=false;
		this.setOnClickListener(this);
		this.setClickable(true);
	}
	public void setChecked(boolean value){
		this.checked=value;
		setValue();
	}
	public boolean isChecked() {
		return checked;
	}
	@Override
	public void onClick(View v) {
		checked=!checked;
		setValue();
		
		if(lsn!=null) lsn.onClick(v);
		
	}
	private void setValue(){
		if(checked){
			this.setImageResource(R.drawable.checktrue);
		}else{
			this.setImageResource(R.drawable.checkfalse);
		}
	}
	public void setOnClickListener(SpecialCheckBox.OnClickListener lsn){
		this.lsn=lsn;
	}
	public interface OnClickListener{
		public void onClick(View v);
	}
	
}
